<template>
  <div class="detail">
    <HmHeader showArrow @clickLeft="fn"> 面经详情 </HmHeader>
    <h1>{{ obj.stem }}</h1>
    <div class="info">
      <span>{{ obj.createdAt }}</span>
      <span>|</span>
      <span>{{ obj.views }} 浏览量</span>
      <span>|</span>
      <span>{{ obj.likeCount }} 点赞数</span>
    </div>

    <div class="qian">
      <img :src="obj.creatorAvatar" alt="" />
      <span>{{ obj.creatorName }}</span>
    </div>

    <div class="content">
      {{ obj.content }}
    </div>
  </div>
</template>

<script>
// 请求地址: https://mock.boxuegu.com/mock/3083/articles/:id
// 请求方式: get
import axios from "axios";
export default {
  name: "HmDetail",
  data() {
    return {
      obj: {}, // 文章详情对象
    };
  },

  created() {
    // 经典:
    // query传参query收
    // 动态路由传参  改完规则params收
    // console.log(this.$route.params.id)
    this.getDetail(this.$route.params.id);
  },

  methods: {
    async getDetail(id) {
      if (!id) return;

      const res = await axios({
        url: "https://mock.boxuegu.com/mock/3083/articles/" + id,
      });
      console.log(res.data.result);
      this.obj = res.data.result;
    },
    fn() {
      // console.log('使用者自己的逻辑')
      this.$router.back();
      // this.$router.go(-1)
      // alert('点击了返回')
    },
    fn2() {
      alert("点击了登录");
    },
  },
};
</script>

<style lang="less" scoped>
.qian {
  display: flex;
  align-items: center;

  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

.content {
  text-indent: 2em;
}
</style>
